#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
//#include <unordered_map>
//#include <unordered_set>
#include <ctime>
//#include "close_hash.hpp"
//#include "open_hash.old.hpp"
//#include "open_hash.hpp"
#include "unordered_map.hpp"
#include "unordered_set.hpp"
#include "bitset.hpp"
#include "bloom_filter.hpp"
using namespace std;
using namespace test;

void test_unordered_set()
{
    unordered_set<int> s;
    s.insert(1);
    s.insert(3);
    s.insert(7);
    s.insert(4);
    s.insert(2);

    unordered_set<int>::iterator it = s.begin();
    while (it != s.end())
    {
        cout << *it << " ";
        ++it;
    }
    cout << endl;
}

void test_unordered_map()
{
    string arr[]
        = {"xg","xg","pg","xg","pg","pg","xg","pg","xj","pg","xj","li"};

    unordered_map<string, int> count_map;
    for (auto& e : arr)
    {
        unordered_map<string, int>::iterator ret = count_map.find(e);
        if (ret == count_map.end())
        {
            count_map.insert(make_pair(e, 1));
        }
        else
        {
            ret->second++;
        }
    }

    for (auto& e : arr)
    {
        count_map[e]++;
    }

    for (auto& kv: count_map)
    {
        cout << kv.first << ": " << kv.second << endl;
    }
}

void test_efficiency()
{
    int n = 10000000;
    vector<int> v;
    srand((unsigned int)time(nullptr));

    for (int i = 0; i < n; i++)
        v.push_back(rand()+i);
        //v.push_back(i);

    set<int> s;
    unordered_set<int> us;

    int begin1 = clock();
    for (auto e : v) s.insert(e);
    int end1 = clock();
    int begin2 = clock();
    for (auto e : v) us.insert(e);
    int end2 = clock();

    cout << "          set insert: " << end1 - begin1 << endl;
    cout << "unordered_set insert: " << end2 - begin2 << endl;

    int begin3 = clock();
    for (auto e : v) s.erase(e);
    int end3 = clock();
    int begin4 = clock();
    for (auto e : v) us.erase(e);
    int end4 = clock();

    cout << "          set erase: " << end3 - begin3 << endl;
    cout << "unordered_set erase: " << end4 - begin4 << endl;
}

int main()
{
    // test_unordered_set();
    // test_unordered_map();
    // test_efficiency();

    // old::test_hash_1();
    // old::test_hash_2();

    // test::test_unordered_set();
    // test::test_unordered_map();

    // test::test_bit_set();
    test::test_bloom_filter();
    test::test_false_positive_rate();


    return 0;
}
